package com.sunny.myproject.storem.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.sunny.myproject.core.base.action.BaseAction;
import com.sunny.myproject.storem.entity.MaterielPrice;
import com.sunny.myproject.storem.service.MaterielPriceService;


@Controller
@RequestMapping("/storem/materielPrice")
public class MaterielPriceAction extends BaseAction<MaterielPrice>{

	private String title = "物料价格";
	private String action = "storem/materielPrice";
	private String function = "materielPrice";

	private Logger logger = Logger.getLogger(MaterielPriceAction.class);
	
	@Autowired
	private MaterielPriceService service;
	
	@Override
	@RequestMapping(params="list")
	public String list(Model model, HttpServletRequest request,
			HttpServletResponse response) {
		try {
			super.pager = super.pageStart(model, request, response, action,
					function, title);
			super.pager = super.pageEnd(model, service.num(criterions), pager);
			super.returnValue(model, service.find(criterions, pager));
		} catch (Exception e) {
			logger.error(e);
		}
		return "storem/materielPriceList";
	}

	@Override
	@RequestMapping(params="add")
	public String add(HttpServletRequest request, HttpServletResponse response) {
		super.add(title, request);
		return "storem/materielPriceEdit";
	}

	@Override
	@RequestMapping(params="edit")
	public String edit(Model model, HttpServletRequest request,
			HttpServletResponse response) {
		try {
			super.returnValue(model,
					service.findById(super.edit(title, model, request)));
		} catch (Exception e) {
			logger.error(e);
		}
		return "storem/materielPriceEdit";
	}

	@Override
	@RequestMapping(params="delete")
	public String delete(HttpServletRequest request,
			HttpServletResponse response) {
		try {
			service.deleteByIds(super.param2(request));
		} catch (Exception e) {
			logger.error(e);
		}
		return "redirect:/storem/materielPrice?list";
	}

	@Override
	@RequestMapping(params="save")
	public String save(HttpServletRequest request,
			HttpServletResponse response, MaterielPrice t) {
		try {
			service.save(t);
		} catch (Exception e) {
			logger.error(e);
		}
		return "redirect:/storem/materielPrice?list";
	}

	@Override
	@RequestMapping(params="view")
	public String view(Model model, HttpServletRequest request,
			HttpServletResponse response) {
		try {
			super.returnViewValue(model,
					service.findById(super.view(title, model, request)));
		} catch (Exception e) {
			logger.error(e);
		}
		return "storem/materielPriceEdit";
	}

}
